import { legacy_createStore as createStore, combineReducers, applyMiddleware } from 'redux'
import userReducer from './user'

import logger from 'redux-logger'

// 合并reducer
const reducer = combineReducers({
	user: userReducer
})

// 创建仓库
const store = createStore(reducer, applyMiddleware(logger))

// 订阅仓库
store.subscribe(() => {
	const state = store.getState();
	localStorage.setItem('user', JSON.stringify(state.user));
})

export default store